var layer;
var $;
layui.use(['layedit','laydate','layer','util','table'], function() {
    $ = layui.$;
    layer = layui.layer,
        util = layui.util;
    var laydate = layui.laydate;
    var table = layui.table

    //刷新按钮
    $("#refreshs").on('click',function(){
        window.location.reload();
    })
    //返回按钮
    $("#back").on('click',function(){
        history.back(-1);
    })

    getTotal(3,2);
    function getTotal(result1,result2){
        $.ajax({
            url:"/personnel/getTotal",//后台路径
            type:"post",
            dataType:"json",
            data:{"result1":result1,"result2":result2,},
            success:function(data){
                $("#BNum").html(data.obj.beforeNumber);
                $("#ANum").html(data.obj.afterNumber);
            }
        })
    }


    selTab(3);
    //待审核 已审核 已驳回
    $("#before").on('click',function(){
        $("#before").removeClass("layui-btn-primary");
        $("#after").addClass("layui-btn-primary");
        $("input[name=result]").val(3);
        selTab(3);
    })
    $("#after").on('click',function(){
        $("#before").addClass("layui-btn-primary");
        $("#after").removeClass("layui-btn-primary");
        $("input[name=result]").val(2);
        SelTab(2);
    })

    //前台用户
    function selTab(loginType){
        $.ajax({
            url:"/personnel/ConLog ",//前台用户路径
            type:"post",
            dataType:"json",
            data:{"loginType":loginType},
            success:function(data){
                selTable(data.obj);

            }
        })
    }

    //后台用户
    function SelTab(loginType){
        $.ajax({
            url:"/personnel/GetTab ",//后台用户登录日志路径
            type:"post",
            dataType:"json",
            data:{"loginType":loginType},
            success:function(data){
                SelTable(data.obj);

            }
        })
    }
    $("#chaxun").on('click',function(){
        var loginLocation=$("#loginLocation").val();
        var loginState=$("#loginState").val();
        var userName=$("#userName").val();
        var result=$("#result").val();
        if(result=="3"){
            query(loginLocation,loginState,userName,result);
        }else if(result=="2"){
            Query(loginLocation,loginState,userName,result);
        }
    })
    //查询前台用户表
    function query(loginLocation,loginState,userName,result){
        $.ajax({
            url:"/personnel/deskUser ",//前台用户路径
            type:"post",
            dataType:"json",
            data:{"loginLocation":loginLocation,"loginState":loginState,"realName":userName,"loginType":result},
            success:function(data){
                selTable(data.obj);

            }
        })
    }
    //查询后台用户表
    function Query(loginLocation,loginState,userName,result){
        $.ajax({
            url:"/personnel/Background ",//后台用户路径
            type:"post",
            dataType:"json",
            data:{"loginLocation":loginLocation,"loginState":loginState,"trueName":userName,"loginType":result},
            success:function(data){
                SelTable(data.obj);

            }
        })
    }
    //前台用户表
    function selTable(data){
        //设备分页table
        table.render({
            elem: "#loginLog",//容器
            data:data,
            title: "数据列表",
            limit: 10,//分页显示条数
            width: 1224,
            page: true,
            toolbar: true,
            cols: [[//定义列
                {
                    title: "Id", fixed: 'left', align: 'center', width: 140, templet: function (data) {
                        return data.id;
                    }
                },
                {field: "id", hide: true},
                {field: 'realName', title: "用户昵称", align: 'center', width: 170},
                {field: 'loginIp', title: "登录IP地址", align: 'center', width: 250},
                {field: 'loginLocation', title: "登录地点", align: 'center', width: 200},
                {
                    field: 'loginDate', title: "登陆日期", align: 'center', width: 250, templet: function (data) {
                        return  data.loginDate;
                    }
                },
                {
                    field: 'loginState', title: '登陆状态', align: 'center', width: 206, templet: function (data) {
                        if (data.loginState == 2) {
                            return "登陆成功"
                        } else {
                            return "登陆失败"
                        }
                    }
                }

            ]]
        })
    }
    //后台用户表
    function SelTable(data){
        //设备分页table
        table.render({
            elem: "#loginLog",//容器
            data:data,
            title: "数据列表",
            limit: 10,//分页显示条数
            width: 1224,
            page: true,
            toolbar: true,
            cols: [[//定义列
                {
                    title: "Id", fixed: 'left', align: 'center', width: 140, templet: function (data) {
                        return data.id;
                    }
                },
                {field: "id", hide: true},
                {field: 'trueName', title: "用户昵称", align: 'center', width: 170},
                {field: 'loginIp', title: "登录IP地址", align: 'center', width: 250},
                {field: 'loginLocation', title: "登录地点", align: 'center', width: 200},
                {
                    field: 'loginDate', title: "登陆日期", align: 'center', width: 250, templet: function (data) {
                        return  data.loginDate;
                    }
                },
                {
                    field: 'loginState', title: '登陆状态', align: 'center', width: 206, templet: function (data) {
                        if (data.loginState == 2) {
                            return "登陆成功"
                        } else {
                            return "登陆失败"
                        }
                    }
                }

            ]]
        })
    }
})